home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PCTAGS15.ARJ / WILDFILE.H < prev   
C/C++ Source or Header  |  1991-09-25  |  11KB  |  255 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: wildfile.h
  5.    Author: J. Kercheval
  6.    Created: Thu, 03/14/1991  20:10:16
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Thu, 03/14/1991  21:15:57  ifdef attribute constants
  12.    J. Kercheval  Sat, 03/16/1991  15:03:54  add FileInfo structure
  13.    J. Kercheval  Sat, 03/16/1991  20:08:41  add status byte
  14.    J. Kercheval  Sun, 03/31/1991  16:15:06  rename time and date defines
  15.    D. Kirschbaum Mon, 05/13/1991  16:32:00  For Turbo C v2.0:
  16.                                             Add <dos.h>
  17.                                             Change some file attribs.
  18. */
  19.  
  20. #ifndef BOOLEAN
  21. #define BOOLEAN int
  22. #define TRUE 1
  23. #define FALSE 0
  24. #endif
  25.  
  26. /*
  27.  
  28.     Dedicated to the Public Domain.  Use this for any purpose for any
  29.     reason with no restrictions, warranties, suitability for fitness
  30.     etc.
  31.  
  32.     Wild File is a module designed to aid the developer in producing
  33.     programs which use a *sensible* wildcard scheme.  For instance
  34.     using this module your command line could specify any SH style
  35.     regular expression which produced a valid file name as input for
  36.     file names.  The only limitation is that since DOS uses the
  37.     literal escape character '\' as a delimiter to specifying a
  38.     directory follow you may not use this character in the command
  39.     line in this routine.
  40.  
  41.     This module assumes compilation on MSC or Borland C (Turbo C, TCC, BCC)
  42. */
  43.  
  44.  
  45. /*----------------------------------------------------------------------------
  46. *
  47. *
  48. *  These routines allow the use of  multiple search threads.  Simply
  49. *  declare a variable to be of type FileInfo (perhaps called ff), fill
  50. *  in the file_pattern and the file_attributes fields (ie.
  51. *  ff.file_pattern and ff.file_attributes), initiate the search with
  52. *  find_firstfile() and continue the search with find_nextfile().  There
  53. *  is no reason why you could not conduct more than one search
  54. *  simultaneously using several different variables.
  55. *
  56. *  In general you should not alter any element of the FileInfo structure
  57. *  once find_firstfile() has been called.  You should never alter any
  58. *  element of the file field in the FileInfo structure.  Doing so may
  59. *  make it impossible to continue the search.
  60. *
  61. *  The elements of the FileInfo structure are defined as follows:
  62. *
  63. *      file_pattern      A string representing the search expression
  64. *                        filled in by the caller before the call to
  65. *                        find_firstfile()
  66. *
  67. *      file_attributes   An 8 bit flag representing the file attributes
  68. *                        you are interested in.  This should be created
  69. *                        by using the | operator and the defined
  70. *                        constants below (ie. _FA_HIDDEN | _FA_NORMAL |
  71. *                        _FA_SYSTEM would obtain all files that were
  72. *                        hidden, system or normal (no attribute) files).
  73. *                        This should be filled before the call to
  74. *                        find_firstfile()
  75. *
  76. *      file_path         Derived from the file_pattern feild in
  77. *                        find_firstfile(), this feild represents the
  78. *                        path required to locate the file whose name is
  79. *                        found in file.name as described below
  80. *
  81. *      file              This is a structure defined by most compilers
  82. *                        and its contents are DOS defined.  It is filled
  83. *                        on a call to find_firstfile() or find_nextfile()
  84. *                        and contains specific information about each
  85. *                        file found.  If find_firstfile() or
  86. *                        find_nextfile() return FALSE then this
  87. *                        structure has undefined fields.
  88. *                        The structures elements are defined as:
  89. *
  90. *                            file.name       The name and extension of
  91. *                                            the last file found. Is of
  92. *                                            type char[13].
  93. *
  94. *                            file.size       The size in bytes of the
  95. *                                            last file found. Is of type
  96. *                                            long.
  97. *
  98. *                            file.attributes The ORed attributes of the
  99. *                                            last found file. Is of type
  100. *                                            char.
  101. *
  102. *                            file.datestamp  The data of last modification
  103. *                                            for the last found file. Is
  104. *                                            of type int with bits defined
  105. *                                            as follows:
  106. *                                                bits 0-4    day
  107. *                                                bits 5-8    month
  108. *                                                bits 9-15   years since 1980
  109. *
  110. *                            file.timestamp  The time of last modification
  111. *                                            for the last found file.  Is
  112. *                                            if type int with bits defined
  113. *                                            as follows:
  114. *                                                bits 0-4    seconds div 2
  115. *                                                bits 5-10   minutes
  116. *                                                bits 11-15  hours
  117. *
  118. *      status            Information flags used internally by this module.
  119. *                        There is no user interesting information and this
  120. *                        status byte should not be altered.  Changing this
  121. *                        feild may result in incorrect file matching behavior
  122. *                        by find_nextfile().
  123. *
  124. *  As an example use of these routines refer to the main() function at
  125. *  the end of wildfile.c
  126. *
  127. ----------------------------------------------------------------------------*/
  128.  
  129. #ifdef __TURBOC__
  130. #include <dir.h>
  131. #include <dos.h>                /* v1.14 for FA_RDONLY, etc. */
  132. #define info ffblk
  133. #define attributes ff_attrib
  134. #define timestamp ff_ftime
  135. #define datestamp ff_fdate
  136. #define size ff_fsize
  137. #define name ff_name
  138. #else
  139. #include <dos.h>
  140. #define info find_t
  141. #define attributes attrib
  142. #define timestamp wr_time
  143. #define datestamp wr_date
  144. #define size size
  145. #define name name
  146. #define MAXPATH   80
  147. #endif
  148.  
  149. struct file_info_struct {
  150.  
  151.     /* thest elements should be set before the call to find_firstfile() */
  152.     char file_pattern[2 * MAXPATH + 1]; /* the original file pattern */
  153.     char file_attributes;       /* the wanted file attributes */
  154.  
  155.     /* these elements are filled by find_firstfile() and find_nextfile() */
  156.     char file_path[MAXPATH + 1];/* the lead portion of the path */
  157.     struct info file;           /* the file block */
  158.     unsigned char status;       /* internal status information */
  159. };
  160.  
  161. typedef struct file_info_struct FileInfo;
  162.  
  163.  
  164. /*----------------------------------------------------------------------------
  165. *
  166. *  In behavior regarding attributes, these routines differ a bit from the
  167. *  standard DOS calls to findfile and findnext.  These routines will only
  168. *  return files with those attributes you explicitly set.  The
  169. *  standard DOS call will return all normal files in addition to the
  170. *  attributes wanted.  This is a little silly since the behavior is true
  171. *  for only certian attribute bits.  The Volume bit set will not result
  172. *  in the return of normal files.  One side effect of this design
  173. *  decision is that you must explicitly ask for files with normal or
  174. *  *no* attributes.  Believe me this is NOT a hardship.
  175. *
  176. *  To obtain a combination of attributes just or the attribute constants
  177. *  as needed (ie. _FA_NORMAL | _FA_READONLY).  Only those files with a wanted
  178. *  attribute will be returned.  If files without any attributes are wanted
  179. *  then you must or the A_NORMAL constant into the attr parameter (This is
  180. *  different behavior than the standard findfirst, findnext call behavior).
  181. *
  182. *  Note: These constants are defined internally for portability.  The
  183. *  constant used does not change but the various compilers sure have
  184. *  invented enough names for them.  I assume BC (Turbo C) or MSC.
  185. *
  186. *  The file attribute definitions are as follows:
  187. *
  188. *    _FA_READONLY   Search for readonly files
  189. *    _FA_HIDDEN     Search for hidden files
  190. *    _FA_SYSTEM     Search for system files
  191. *    _FA_VOLUME     Search for Volume label
  192. *    _FA_DIRECTORY  Search for Directory
  193. *    _FA_ARCHIVE    Search for non backup up files
  194. *    _FA_NORMAL     Search for all normal files
  195. *
  196. ----------------------------------------------------------------------------*/
  197.  
  198. /* if not using Borland C then assume MSC */
  199.  
  200. #ifdef __TURBOC__
  201. #define _FA_READONLY  FA_RDONLY /* FA_READONLY v1.14 */
  202. #define _FA_HIDDEN    FA_HIDDEN
  203. #define _FA_SYSTEM    FA_SYSTEM
  204. #define _FA_VOLUME    FA_VOLUME
  205. #define _FA_DIRECTORY FA_DIREC  /* FA_DIRECTORY v1.14 */
  206. #define _FA_ARCHIVE   FA_ARCH   /* FA_ARCHIVE v1.14 */
  207. #define _FA_NORMAL    0x40
  208. #else
  209. #define _FA_READONLY  _A_RDONLY
  210. #define _FA_HIDDEN    _A_HIDDEN
  211. #define _FA_SYSTEM    _A_SYSTEM
  212. #define _FA_VOLUME    _A_VOLID
  213. #define _FA_DIRECTORY _A_SUBDIR
  214. #define _FA_ARCHIVE   _A_ARCH
  215. #define _FA_NORMAL    0x40
  216. #endif
  217.  
  218.  
  219. /*----------------------------------------------------------------------------
  220. *
  221. *  find_firstfile() will find the first file matching file_pattern.
  222. *  find_nextfile() will find the next file matching the name specified
  223. *  by find_firstfile().  The routines will return the BOOLEAN value FALSE
  224. *  if the file is not found in the call to  find_firstfile() or if there are
  225. *  no more files found in a call to find_nextfile.  If a file is found then
  226. *  both routines will return the BOOLEAN value TRUE.
  227. *
  228. *  file_pattern may be SH style regular expressions.  The regular expression
  229. *  symbols allowed are:
  230. *
  231. *       '*' -- Matches any set of zero or more characters
  232. *       '?' -- Matches any single character
  233. *       [SET] matches any character in the specified set,
  234. *       [!SET] or [^SET] matches any character not in the specified set.
  235. *       \ is allowed within a set to escape a character like ']' or '-'
  236. *
  237. *  A set is composed of characters or ranges; a range looks like
  238. *  character hyphen character (as in 0-9 or A-Z).  [0-9a-zA-Z_] is the
  239. *  minimal set of characters allowed in the [..] pattern construct.
  240. *  Other characters are allowed (ie. 8 bit characters) if your system
  241. *  will support them.
  242. *
  243. *  To suppress the special syntactic significance of any of
  244. *  `[]*?!^-\' within an [..] construct and match the character exactly,
  245. *  precede it with a `\'.
  246. *
  247. *  Parameters:
  248. *       ff - a pointer to a FileInfo structure already allocated or
  249. *            declared.
  250. *
  251. ----------------------------------------------------------------------------*/
  252.  
  253. BOOLEAN find_firstfile(FileInfo * ff);
  254. BOOLEAN find_nextfile(FileInfo * ff);
  255.